home *** CD-ROM | disk | FTP | other *** search
- #include <SWIncludes.h>
- #include <SWGameUtils.h>
- #include <SWApplication.h>
-
- #include "Application.h"
- #include "Shark Attack.h"
- #include "SpriteMoveProcs.h"
- #include "NewSprite.h"
- #include "SpriteCollideProcs.h"
- #include "Stats.h"
- #include "GlobalVariables.h"
-
-
- // Pointers to the original sprites which we clone
- // when we want to add a sprite to the animation.
- // We never add these sprites themselves to the animation.
-
- SpritePtr gMasterSubSpriteP,
- gMasterBulletSpriteP,
- gMasterFishSpriteP,
- gMasterSharkSpriteP,
- gMasterTitleSpriteP;
-
-
- #define kFishStrength 2 // Number of shots it takes to kill a fish
- #define kSharkStrength 15 // Number of shots it takes to kill a shark
-
-
- ///--------------------------------------------------------------------------------------
- // LoadSprites
- ///--------------------------------------------------------------------------------------
-
- void LoadSprites( void )
- {
- OSErr err;
-
- // Load gMasterSubSpriteP
- err = SWCreateSpriteFromCicnResource(gSpriteWorldP, &gMasterSubSpriteP,
- NULL, 128, 2, kFatMask);
- FatalError(err);
- SetUpSprite(gMasterSubSpriteP);
-
- // Load gMasterBulletSpriteP
- err = SWCreateSpriteFromCicnResource(gSpriteWorldP, &gMasterBulletSpriteP,
- NULL, 130, 1, kFatMask);
- FatalError(err);
- SetUpSprite(gMasterBulletSpriteP);
-
- // Load gMasterFishSpriteP
- err = SWCreateSpriteFromPictResource(gSpriteWorldP, &gMasterFishSpriteP,
- NULL, 300, 300, 6, kFatMask);
- FatalError(err);
- SetUpSprite(gMasterFishSpriteP);
-
-
- // Load gMasterSharkSpriteP
- err = SWCreateSpriteFromPictResource(gSpriteWorldP, &gMasterSharkSpriteP,
- NULL, 200, 200, 6, kFatMask);
- FatalError(err);
- SetUpSprite(gMasterSharkSpriteP);
-
- // Load gMasterTitleSpriteP
- err = SWCreateSpriteFromPictResource(gSpriteWorldP, &gMasterTitleSpriteP,
- NULL, 128, 128, 1, kFatMask);
- FatalError(err);
- SetUpSprite(gMasterTitleSpriteP);
- }
-
-
- ///--------------------------------------------------------------------------------------
- // DisposeSprites - we must dispose of each sprite we loaded, since they are not
- // added to the SpriteWorld, and therefore will not be disposed with the SpriteWorld.
- ///--------------------------------------------------------------------------------------
-
- void DisposeSprites( void )
- {
- SWDisposeSprite(&gMasterSubSpriteP);
- SWDisposeSprite(&gMasterBulletSpriteP);
- SWDisposeSprite(&gMasterFishSpriteP);
- SWDisposeSprite(&gMasterSharkSpriteP);
- SWDisposeSprite(&gMasterTitleSpriteP);
- }
-
-
- ///--------------------------------------------------------------------------------------
- // SetUpSprite - makes the LoadSprites code a little cleaner.
- ///--------------------------------------------------------------------------------------
-
- void SetUpSprite(SpritePtr mySpriteP)
- {
- Rect moveBoundsRect;
-
- if (gSpriteWorldP->pixelDepth == 8)
- SWCompileSprite(mySpriteP);
-
- // we have to do this since the game rect is smaller than the title screen rect
- moveBoundsRect = gSpriteWorldP->backRect;
- moveBoundsRect.bottom -= kStatsHeight;
- SWSetSpriteMoveBounds(mySpriteP, &moveBoundsRect);
- SWSetSpriteDrawProc(mySpriteP, gSpriteMaskDrawProc);
- SWLockSprite(mySpriteP);
- }
-
-
- ///--------------------------------------------------------------------------------------
- // NewSubSprite - clone the master sprite and add the clone to the animation.
- // Also allocate memory for the custom sprite structure.
- ///--------------------------------------------------------------------------------------
-
- SpritePtr NewSubSprite( void )
- {
- SubStructPtr subStructP;
- SpritePtr subSpriteP;
- OSErr err;
-
- // Allocate memory for the SubStruct
- subStructP = (SubStructPtr)NewPtr(sizeof(SubStruct));
- FatalError( MemError() );
-
- err = SWCloneSprite(gMasterSubSpriteP, &subSpriteP, subStructP);
- FatalError(err);
-
- SWAddSprite(gSubSpriteLayerP, subSpriteP);
- SWSetSpriteMoveProc(subSpriteP, SubSpriteMoveProc);
- SWSetSpriteCollideProc(subSpriteP, SubSpriteCollideProc);
-
- subStructP->horizDelta = 0;
- subStructP->vertDelta = 0;
- subStructP->horizPos = gSpriteWorldP->backRect.right/2-20;
- subStructP->vertPos = gSpriteWorldP->backRect.bottom/2-20;
-
- subStructP->curDirection = kLeftDirection;
- subStructP->numBulletsOnScreen = 0;
- subStructP->nextShotDelay = 0;
- subStructP->canShoot = true;
-
- return subSpriteP;
- }
-
-
- ///--------------------------------------------------------------------------------------
- // NewBulletSprite - clone the master sprite and add the clone to the animation.
- // Also allocate memory for the custom sprite structure.
- ///--------------------------------------------------------------------------------------
-
- SpritePtr NewBulletSprite( void )
- {
- BulletStructPtr bulletStructP;
- SpritePtr bulletSpriteP;
- OSErr err;
-
- // Allocate memory for the BulletStruct
- bulletStructP = (BulletStructPtr)NewPtr(sizeof(BulletStruct));
- FatalError( MemError() );
-
- err = SWCloneSprite(gMasterBulletSpriteP, &bulletSpriteP, bulletStructP);
- FatalError(err);
-
- SWAddSprite(gBulletSpriteLayerP, bulletSpriteP);
- SWSetSpriteMoveProc(bulletSpriteP, BulletSpriteMoveProc);
-
- return bulletSpriteP;
- }
-
-
- ///--------------------------------------------------------------------------------------
- // NewFishSprite - clone the master sprite and add the clone to the animation.
- // Also allocate memory for the custom sprite structure.
- ///--------------------------------------------------------------------------------------
-
- SpritePtr NewFishSprite( void )
- {
- FishStructPtr fishStructP;
- SpritePtr fishSpriteP;
- OSErr err;
-
- // Allocate memory for the FishStruct
- fishStructP = (FishStructPtr)NewPtr(sizeof(FishStruct));
- FatalError( MemError() );
-
- err = SWCloneSprite(gMasterFishSpriteP, &fishSpriteP, fishStructP);
- FatalError(err);
-
- SWAddSprite(gFishSpriteLayerP, fishSpriteP);
- SWSetSpriteMoveProc(fishSpriteP, FishSpriteMoveProc);
- SWSetSpriteCollideProc(fishSpriteP, FishSpriteCollideProc);
- SWSetSpriteFrameTime(fishSpriteP, 1000/15);
- SWSetSpriteFrameAdvanceMode(fishSpriteP, kSWPatrollingMode);
-
- fishStructP->energy = kFishStrength;
- gNumFishOnScreen++;
- fishStructP->moveDelay = 0;
- fishStructP->hitCounter = 0;
-
- return fishSpriteP;
- }
-
-
- ///--------------------------------------------------------------------------------------
- // NewSharkSprite - clone the master sprite and add the clone to the animation.
- // Also allocate memory for the custom sprite structure.
- ///--------------------------------------------------------------------------------------
-
- SpritePtr NewSharkSprite( void )
- {
- SharkStructPtr sharkStructP;
- SpritePtr sharkSpriteP;
- OSErr err;
-
- // Allocate memory for the SharkStruct
- sharkStructP = (SharkStructPtr)NewPtr(sizeof(SharkStruct));
- FatalError( MemError() );
-
- err = SWCloneSprite(gMasterSharkSpriteP, &sharkSpriteP, sharkStructP);
- FatalError(err);
-
- SWAddSprite(gSharkSpriteLayerP, sharkSpriteP);
- SWSetSpriteMoveProc(sharkSpriteP, SharkSpriteMoveProc);
- SWSetSpriteCollideProc(sharkSpriteP, SharkSpriteCollideProc);
- SWSetSpriteFrameTime(sharkSpriteP, 1000/5);
- SWSetSpriteFrameAdvanceMode(sharkSpriteP, kSWPatrollingMode);
-
- sharkStructP->horizDelta = 0;
- sharkStructP->vertDelta = 0;
-
- sharkStructP->energy = kSharkStrength;
- sharkStructP->moveDelay = 0;
- sharkStructP->hitCounter = 0;
- gNumSharksOnScreen++;
-
- return sharkSpriteP;
- }
-
-
- ///--------------------------------------------------------------------------------------
- // AddTitleSprite
- ///--------------------------------------------------------------------------------------
-
- void AddTitleSprite( void )
- {
- SpritePtr titleSpriteP;
- Rect titleSpriteRect;
- OSErr err;
-
- err = SWCloneSprite(gMasterTitleSpriteP, &titleSpriteP, NULL);
- FatalError(err);
-
- SWAddSprite(gSubSpriteLayerP, titleSpriteP);
-
- titleSpriteRect = titleSpriteP->curFrameP->frameRect;
- CenterRect(&titleSpriteRect, &gSpriteWorldP->backRect);
- SWSetSpriteLocation(titleSpriteP, titleSpriteRect.left, titleSpriteRect.top);
- }
-
-